﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Game1942.Library.Weapons;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;


namespace Game1942.Library.View
{
    public class WeaponCounterView : IObserver<Algo42>,IView
    {
        private int xPos, yPos;
        private int amountOfRockets = 5, amountOfTorpedos = 5;
        SpriteFont font;
        private IDisposable unsubscriber; 

        public WeaponCounterView(int xPos, int yPos)
        {
            this.xPos = xPos;
            this.yPos = yPos;
        }

        public void LoadContent(SpriteFont font)
        {
            this.font = font;
        }

        public void Draw(SpriteBatch spriteBatch)
        {
            spriteBatch.DrawString(font,"8",new Vector2(xPos - 56,yPos - 57),Color.White,80.11f,
                Vector2.Zero,1.0f,SpriteEffects.None,0.0f );

            spriteBatch.DrawString(font,
                "AMMO",
                new Vector2(xPos - 130, yPos - 90),
                Color.White);

            spriteBatch.DrawString(font,
                "LASERS x ",
                new Vector2(xPos - 130, yPos - 70),
                Color.White);

            spriteBatch.DrawString(font,
                "ROCKETS x " + amountOfRockets,
                new Vector2(xPos - 130, yPos - 50),
                Color.White);
           
            spriteBatch.DrawString(font,
                "TORPEDOS x " + amountOfTorpedos,
                new Vector2(xPos - 130, yPos - 30),
                Color.White);
        }

        public bool Visible()
        {
            throw new NotImplementedException();
        }

        #region [Observer Methods]

        public void Subscribe(IObservable<Algo42> provider)
        {
            if (provider != null)
                unsubscriber = provider.Subscribe(this);
        }

        //Provides the observer with new data.
        public void OnNext(Algo42 value)
        {
            amountOfRockets = value.AmountOfRockets;
            amountOfTorpedos = value.AmountOfTorpedos;
        }


        public void OnError(Exception error)
        {
            //Do nothing
        }

        //Notifies the observer that the provider has finished sending push-based notifications.
        public void OnCompleted()
        {
            unsubscriber.Dispose();
        }

        #endregion
    }
}
